{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5a07e720",
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "from imgcompresser import ImageCompressor,setup_logging\n",
    "ic=ImageCompressor(compress_threshold=500)\n",
    "setup_logging(level=logging.INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ed9b897",
   "metadata": {},
   "outputs": [],
   "source": [
    "p=r\"S:\\imgs_demo\\CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.png\"\n",
    "jpg1=r\"S:/imgs_demo/LockScreen___1920_1080_notdimmed.jpg\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "53248d9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-23 22:00:07,117 - imgcompresser - INFO - 文件大小(7.02KB)过小,微压(quality=70)\n",
      "2025-05-23 22:00:07,123 - imgcompresser - INFO - 文件大小(44.50KB)过小,微压(quality=70)\n",
      "2025-05-23 22:00:07,130 - imgcompresser - INFO - 文件大小(21.06KB)过小,微压(quality=70)\n",
      "2025-05-23 22:00:07,239 - imgcompresser - INFO - 节省: 37.77%原始大小: 7.02KB, 压缩后: 4.37KB, 压缩成功: S:/imgs_demo/5bb9fc66300ae2ba3e9960e2175a2b8d_1200x1200.webp -> ./compressed/5bb9fc66300ae2ba3e9960e2175a2b8d_1200x1200.webp\n",
      "压缩参数: quality=70\n",
      "2025-05-23 22:00:07,265 - imgcompresser - INFO - 节省: 16.44%原始大小: 21.06KB, 压缩后: 17.60KB, 压缩成功: S:/imgs_demo/fxr_podium_mx_pants_750x750.webp -> ./compressed/fxr_podium_mx_pants_750x750.webp\n",
      "压缩参数: quality=70\n",
      "2025-05-23 22:00:07,376 - imgcompresser - INFO - 节省: 96.88%原始大小: 1555.88KB, 压缩后: 48.51KB, 压缩成功: S:/imgs_demo/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.png -> ./compressed/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp\n",
      "压缩参数: quality=20\n",
      "2025-05-23 22:00:07,380 - imgcompresser - INFO - 节省: -37.27%原始大小: 44.50KB, 压缩后: 61.09KB, 压缩成功: S:/imgs_demo/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp -> ./compressed/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp\n",
      "压缩参数: quality=70\n",
      "2025-05-23 22:00:07,498 - imgcompresser - INFO - 节省: 97.61%原始大小: 3505.10KB, 压缩后: 83.69KB, 压缩成功: S:/imgs_demo/LockScreen___1920_1080_notdimmed.jpg -> ./compressed/LockScreen___1920_1080_notdimmed.webp\n",
      "压缩参数: quality=20\n",
      "2025-05-23 22:00:07,521 - imgcompresser - INFO - 节省: 99.58%原始大小: 9591.31KB, 压缩后: 40.61KB, 压缩成功: S:/imgs_demo/9B75D542-166A-489C-9083-47A18447F2B9_0fa79188-99a4-4035-b62c-265dfc4e54a9.png -> ./compressed/9B75D542-166A-489C-9083-47A18447F2B9_0fa79188-99a4-4035-b62c-265dfc4e54a9.webp\n",
      "压缩参数: quality=20\n",
      "2025-05-23 22:00:08,497 - imgcompresser - INFO - 节省: 96.33%原始大小: 3063.23KB, 压缩后: 112.28KB, 压缩成功: S:/imgs_demo/Plasticbunkwrap 009.JPG -> ./compressed/Plasticbunkwrap 009.webp\n",
      "压缩参数: quality=20\n",
      "2025-05-23 22:00:09,536 - imgcompresser - INFO - 节省: 80.20%原始大小: 1993.07KB, 压缩后: 394.54KB, 压缩成功: S:/imgs_demo/swan-5838427.jpg -> ./compressed/swan-5838427.webp\n",
      "压缩参数: quality=20\n",
      "2025-05-23 22:00:09,557 - imgcompresser - INFO - 节省: 74.08%原始大小: 4056.31KB, 压缩后: 1051.48KB, 压缩成功: S:/imgs_demo/DRONE_Saturday_Jan_HQ-67_2_8e376ed4-4334-4b4b-9cb9-f5b0e37d88f0.jpg -> ./compressed/DRONE_Saturday_Jan_HQ-67_2_8e376ed4-4334-4b4b-9cb9-f5b0e37d88f0.webp\n",
      "压缩参数: quality=20\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'total': 9,\n",
       " 'success': 9,\n",
       " 'failed': 0,\n",
       " 'skipped': 0,\n",
       " 'details': ['节省: 37.77%原始大小: 7.02KB, 压缩后: 4.37KB, 压缩成功: S:/imgs_demo/5bb9fc66300ae2ba3e9960e2175a2b8d_1200x1200.webp -> ./compressed/5bb9fc66300ae2ba3e9960e2175a2b8d_1200x1200.webp\\n压缩参数: quality=70',\n",
       "  '节省: 16.44%原始大小: 21.06KB, 压缩后: 17.60KB, 压缩成功: S:/imgs_demo/fxr_podium_mx_pants_750x750.webp -> ./compressed/fxr_podium_mx_pants_750x750.webp\\n压缩参数: quality=70',\n",
       "  '节省: 96.88%原始大小: 1555.88KB, 压缩后: 48.51KB, 压缩成功: S:/imgs_demo/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.png -> ./compressed/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp\\n压缩参数: quality=20',\n",
       "  '节省: -37.27%原始大小: 44.50KB, 压缩后: 61.09KB, 压缩成功: S:/imgs_demo/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp -> ./compressed/CA4E736E-6F0F-4D62-ABA5-BF889276CBE3.webp\\n压缩参数: quality=70',\n",
       "  '节省: 97.61%原始大小: 3505.10KB, 压缩后: 83.69KB, 压缩成功: S:/imgs_demo/LockScreen___1920_1080_notdimmed.jpg -> ./compressed/LockScreen___1920_1080_notdimmed.webp\\n压缩参数: quality=20',\n",
       "  '节省: 99.58%原始大小: 9591.31KB, 压缩后: 40.61KB, 压缩成功: S:/imgs_demo/9B75D542-166A-489C-9083-47A18447F2B9_0fa79188-99a4-4035-b62c-265dfc4e54a9.png -> ./compressed/9B75D542-166A-489C-9083-47A18447F2B9_0fa79188-99a4-4035-b62c-265dfc4e54a9.webp\\n压缩参数: quality=20',\n",
       "  '节省: 96.33%原始大小: 3063.23KB, 压缩后: 112.28KB, 压缩成功: S:/imgs_demo/Plasticbunkwrap 009.JPG -> ./compressed/Plasticbunkwrap 009.webp\\n压缩参数: quality=20',\n",
       "  '节省: 80.20%原始大小: 1993.07KB, 压缩后: 394.54KB, 压缩成功: S:/imgs_demo/swan-5838427.jpg -> ./compressed/swan-5838427.webp\\n压缩参数: quality=20',\n",
       "  '节省: 74.08%原始大小: 4056.31KB, 压缩后: 1051.48KB, 压缩成功: S:/imgs_demo/DRONE_Saturday_Jan_HQ-67_2_8e376ed4-4334-4b4b-9cb9-f5b0e37d88f0.jpg -> ./compressed/DRONE_Saturday_Jan_HQ-67_2_8e376ed4-4334-4b4b-9cb9-f5b0e37d88f0.webp\\n压缩参数: quality=20']}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img_dir=r\"S:/imgs_demo/\"\n",
    "ic.batch_compress(img_dir,output_dir=\"./compressed/\",overwrite=True,quality=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "401ed560",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "257d05cc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
